<?php
namespace app\shawting\controller;

use think\Session;

class basic extends Base
{
    public function service(){
        $arr = db("city_service_setting")->paginate(10,false, ['query'=> request()->param()]/*不丢失已存在的url参数]*/);
        $this->assign("arr",$arr);
        return $this->fetch();
    }

    public function ajax_service_edit(){
        $id = input("id");
        $remark = input("remark");
        if(!is_numeric($id) || mb_strlen($remark,'UTF8') > 20){
            return $this->error("说明文字长度能超过20个");
        }
        $result = db("city_service_setting")->where(["id"=>$id])->update(['remark'=>$remark]);
        if($result){
            return $this->success("操作成功");
        }else{
            return $this->error("操作失败");
        }
    }

    public function advice(){
        $search = input('search')?input('search'):"";
        $where["title|context"] = ["like","%{$search}%"];
        $arr = db("city_advice")
            ->where($where)
            ->paginate(10,false, ['query'=> request()->param()]/*不丢失已存在的url参数]*/);
        $this->assign("arr",$arr);
        $this->assign("search",$search);
        return $this->fetch();
    }

    public function ajax_advice_reply(){
        $id = input("id");
        $reply_title = input("reply_title");
        $reply_context = input("reply_context");
        $data = [
            "id" => $id,
            "reply_title" => $reply_title,
            "reply_context" => $reply_context,
            "reply_time" => date("Y-m-d H:i:s",time()),
            "reply_by" => session("admin_name"),
        ];
        $re = db("city_advice")->update($data);
        if($re){
            return $this->success("回复成功");
        }else{
            return $this->error("回复失败");
        }
    }

    public function ajax_advice_delete(){
        $id = input("id");
        if(!is_numeric($id)){
            return $this->error('查询数据格式不正确');
        }
        $re = db("city_advice")->delete(["id"=>$id]);

        if($re){
            return $this->success("操作成功");
        }else{
            return $this->error("操作失败");
        }
    }

    public function aboutUs(){
        return $this->fetch();
    }

    public function technical(){
        return $this->fetch();
    }

    public function  ajax_submit_insert(){
        $data = input();
        $re = db("city_setting")->insert($data);
        if($re){
            return $this->success("操作成功");
        }else{
            return $this->error("操作失败");
        }
    }









}